<template>
	<view class="content-header">
		<view class="content-top flex-column">
			<view class="ones flex-column" v-for="item in list">
				<view class="flex-row flex-content-between">
					<view class="header flex-row flex-item-center">
						<image :src="$utils.cdnImg(item.user.avatar)" mode="scaleToFill"></image>
						<view>{{item.user.nickname}}</view>
					</view>
					<view class="createtime">{{item.createtime}}</view>
				</view>
				<view class="text">
					<view class="text-top">{{item.content}}</view>
				</view>
				<view class="img" v-if="item.images.length>0">
					<image v-for="img in item.images" :src="$utils.cdnImg(img)" mode=""></image>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default{
		data(){
			return {
				goods_id:"",
				page:1,
				list:[],
			}
		},
		onLoad(opt) {
			if(opt.id){
				this.goods_id = opt.id
			}
			this.getGoodsComment();
		},
		onReachBottom(){
			this.getGoodsComment();
		},
		onPullDownRefresh() {
			this.page = 1
			this.list = []
			this.getGoodsComment(()=>{
				uni.stopPullDownRefresh();
			})
		},
		methods:{
			/**
			 * 获取商品评论
			 */
			getGoodsComment(callback){
				let data = {
					page:this.page,
					goods_id:this.goods_id
				}
				if(data.page==0){
					return
				}
				let that = this
				this.$api.getGoodsComment(data).then(res=>{
					console.log(res);
					if(res.data.length>0){
						that.list.push(...res.data)
						that.page+=1
					}else{
						that.page = 0
					}
				}).finally(e=>{
					if(typeof callback == 'function'){
						callback()
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.img{
		margin-left: 76rpx;
		margin-top: 20rpx;
		image{
			width: 100rpx;
			height: 100rpx;
			margin-right: 20rpx;
		}
	}
	.text{
		margin-left: 76rpx;
		margin-top: 24rpx;
		.text-top{
			font-size: 28rpx;
			font-family: PingFang SC-Regular, PingFang SC;
			font-weight: 400;
			color: #666666;
		}
	}
	.createtime{
		font-size: 24rpx;
		font-family: PingFang SC-Regular, PingFang SC;
		font-weight: 400;
		color: #999999;
	}
	.header{
		>image{
			width: 62rpx;
			height: 62rpx;
			border-radius: 30rpx;
		}
		>view{
			font-size: 28rpx;
			font-family: PingFang SC-Regular, PingFang SC;
			font-weight: 400;
			color: #333333;
			margin-left: 14rpx;
		}
	}
	.ones{
		width: 690rpx;
		// height: 196rpx;
		margin-top: 50rpx;
		border-bottom: 1rpx solid #EFEFEF;
		padding-bottom: 30rpx;
	}
	.content-top{
		width: 690rpx;
		margin-left: 30rpx;
	}
</style>